﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace DataAccess.Repository
{
    public partial class RepositoryFactory<TDbContext, TEntity> : IRepositoryBase<TEntity> where TDbContext : DbContext, new() where TEntity : class, new()
    {


        /// <summary>
        /// 获取DataTable
        /// </summary>
        /// <param name="sql">sql命令</param>
        /// <returns></returns>
        public DataTable GetDataTable(string sql)
        {
            MySqlConnection sqlconnection = new MySqlConnection(dbContext.Database.Connection.ConnectionString);
            MySqlDataAdapter sqlDataAdapter = new MySqlDataAdapter(sql, sqlconnection);
            DataSet dataSet = new DataSet();
            sqlDataAdapter.Fill(dataSet);
            DataTable dataTable = dataSet.Tables[0];
            return dataTable;
        }
    }
}
